<?php

namespace App\Http\Controllers;

use App\Models\ProjectComment;
use App\Models\RoleUser;
use App\Models\Throughtrain;
use App\Models\Role;
use App\Models\ThroughtrainComment;
use Illuminate\Http\Request;
use \DB;
use App\Http\Requests;
use App\Http\Controllers\CommonController;
use Illuminate\Http\Response;
use App\Http\Requests\ZtcRequest;
use Illuminate\View\View;
use App\Models\User;
use App\User as aUser;

class ProjectCommentController extends CommonController
{
    public function getIndex(Request $request)
    {
        $data = $request->input();

        $lists = ProjectComment::with('user')->where('project_id', $data['id'])->paginate(10);
        $actions = aUser::getPermissionAction(1301,1);

        return view('project/comment/index')->with('lists', $lists)->with('project_id', $data['id'])
            ->with('actions', $actions);
    }


    public function getEdit(Request $request)
    {
        $data = $request->input();

        $list = ProjectComment::where('id', $data['id'])->first();

        return view('project/comment/edit')->with('list', $list);
    }


    public function postEdit(Request $request)
    {
        $this->validate($request, ['wonderful' => 'required|in:1,0']);

        $data = $request->input();
        $comment =  ProjectComment::where('id', $data['id'])->first();
        ProjectComment::where('id', $data['id'])->update(['wonderful'=>$data['wonderful']]);

        return AjaxCallbackMessage('编辑成功', true, url('projectcomment/index?id='.$comment->project_id));
    }


    public function postDelete(Request $request)
    {
        $data = $request->input();

        $comment =  ProjectComment::where('id', $data['cid'])->first();
        ProjectComment::where('id', $data['cid'])->delete();

        return AjaxCallbackMessage('删除成功', true, url('projectcomment/index?id='.$comment->project_id));
    }
}
